package com.yaowk.web.system.utils;

import com.yaowk.api.system.model.Menu;
import com.yaowk.web.common.model.Tree;

import java.util.List;

public class MenuUtil {
    /**
     * 格式化树结构返回值
     *
     * @param menus
     * @param tree
     */
    public static void findMenuChildren(List<Menu> menus, Tree<Menu, Integer> tree) {
        Integer parentId = tree.getValue().getId();
        for (Menu menu : menus) {
            if (parentId.equals(menu.getParentId())) {
                Tree<Menu, Integer> n = new Tree<>();
                n.setValue(menu);
                n.setKey(menu.getId());
                n.setLabel(menu.getName());
                boolean result = tree.getChildren().add(n);
                if (result) {
                    findMenuChildren(menus, n);
                }
            }
        }
    }
}
